
<template>
  <div class="operation-log">
    <h2 class="page-title">操作日志</h2>

    <!-- 日志列表 -->
    <el-table :data="logList" border style="width: 100%;">
      <el-table-column label="序号" width="80">
        <template #default="{ $index }">
          {{ (currentPage - 1) * pageSize + $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="business" label="操作名称" min-width="150" />
      <el-table-column prop="method" label="调用方法" width="160" />
      <el-table-column prop="status" label="状态" width="80">
        <template #default="{ row }">
          <el-tag :type="row.status === 0 ? 'success' : 'danger'" size="small">
            {{ row.status === 0 ? '成功' : '失败' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="log_content" label="操作详情" min-width="180" />
      <el-table-column prop="real_name" label="操作人" width="140" />
      <el-table-column prop="create_time" label="操作时间" width="300">
        <template #default="{ row }">
          <span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
            {{ row.create_time }}
          </span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"      style="margin-top: 20px;"
    />
  </div>
</template>

<script setup>import { ref, getCurrentInstance } from 'vue';
import { ElMessage } from 'element-plus';

// 状态管理
const { proxy } = getCurrentInstance();
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);

// 日志数据
const logList = ref([]);

// 获取日志数据
const fetchLogs = () => {
  proxy.$axios.get("/log/list", {
    params: {
      pageNum: currentPage.value,
      pageSize: pageSize.value
    }
  }).then((ServerData) => {
    console.log("日志数据获取成功", ServerData);
    logList.value = ServerData.data.data.list;
    total.value = ServerData.data.data.total;
  }).catch((error) => {
    console.log("请求发生异常", error);
    ElMessage.error("日志数据获取失败");
  });
};

// 分页处理
const handleSizeChange = (val) => {
  pageSize.value = val;
  fetchLogs();
};

const handleCurrentChange = (val) => {
  currentPage.value = val;
  fetchLogs();
};

// 页面加载时获取数据
fetchLogs();
</script>

<style scoped>.operation-log {
  padding: 20px;
  background-color: #f5f7fa;
}

.page-title {
  margin-bottom: 20px;
  font-size: 18px;
  font-weight: 500;
  color: #303133;
}

/* 表格样式 */
.el-table {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.el-table th {
  background-color: #f5f7fa;
  color: #909399;
  font-weight: 500;
  text-align: center;
}

.el-table td {
  padding: 12px 16px;
  text-align: center;
}

/* 分页样式 */
.el-pagination {
  margin-top: 20px;
  text-align: center;
}

/* 状态标签样式 */
.el-tag--success {
  background-color: #f0f9eb;
  border-color: #c2e7b0;
  color: #67c23a;
}

.el-tag--danger {
  background-color: #fef0f0;
  border-color: #fbc4c4;
  color: #f56c6c;
}
</style>